


from lxml import etree
from util.selenium.webdriver.common.by import By
from spider_data.spiderBaseMethod import bm
from util.g import g






def parse_cover(driver=None):
    try:
        main_case_loc = (By.LINK_TEXT, '申请书封皮')
        bm.detail_switch_iframe(driver=driver)

        # # # 点击 主要情况表按钮。
        bm.click(driver=driver, ele_loc=main_case_loc)
        # # # 等待标题加载出来
        bm.wait(driver=driver, ele_loc=g.title_loc)

        text = driver.page_source
        tree = etree.HTML(text)
        cert_org = tree.xpath('//div[@id="uniform-centersAuthorized"]/span/text()')
        app_date = tree.xpath('//input[@id="hadate"]/@value')

        WriteApplicationCover = {'cert_org': bm.join_and_repalce(cert_org), 'app_date': bm.str_to_date(s=app_date)}
        # SaveData().update_info(table='ent_yearstatus', value=cover_item)
        # driver.switch_to.default_content()
        return {"key": "WriteApplicationCover", "value": WriteApplicationCover}
    except Exception as err:
        msg = "error: {} file: {} lines: {}".format(err, err.__traceback__.tb_frame.f_globals["__file__"],
                                                    err.__traceback__.tb_lineno)
        g.logger.error(msg)
        raise Exception(msg)